#ifndef __USR_MQTT_H
#define __USR_MQTT_H

#include "osasys.h"

#define MQTT_DEMO_SSL 			1
#define MQTT_DEMO_AUTOCON 		1
#define MQTT_DEMO_PUB_QOS 		1
#define MQTT_DEMO_UART_ID 		1
#define MQTT_DEMO_UART_BAUD 	115200
#pragma pack(1)


/**
 * @brief mqtt
 */
typedef enum {
	MQTT_STATE_DISCONNECT 			,	/**< mqtt  */
	MQTT_STATE_SCONNECT 			,	/**< mqtt socket */
	MQTT_STATE_MQTT					,	/**< mqtt socket */
	MQTT_STATE_READY 					/**< mqtt mqtt*/
}LUAT_MQTT_STATE_E;
#pragma pack(0)

#pragma pack(1)
typedef union
{
    uint8_t data[0];
    struct
    {
        uint8_t move_up_cycle;/* 闁哄鏅滈崝鏇熸叏閳哄懏鍋愰柤鍝ヮ暯閸嬫挻鎷呮搴ｆ啰闂佺缈伴崕閬嶅箠閸℃稑瀚夐柨鐕傛嫹 */
        uint16_t stop_up_cycle;/*闂傚倸鐗婇悷锕傤敆濞戙垺鍋愰柤鍝ヮ暯閸嬫挻鎷呮搴ｆ啰闂佺缈伴崕閬嶅箠閸℃稑瀚夐柨鐕傛嫹*/
        uint8_t product_id[16];
        char ver_hard[16];
        char ver_4g[16];
        char build_time[32];
        char addr[64];
        uint16_t port;
        time_t startup_ts;
        int startup_reason;
        time_t real_ts;
        bool online_flag;
        luat_rtos_mutex_t mutex;
    } info;
} DEV_INFO_T;

#pragma pack(0)
/**
 * mqtt server mod type
 */
typedef enum
{
    ONLINE = 0,//婵犵數濮烽弫鎼佸磻閻愬搫鍨傞柛顐ｆ礀缁犱即鏌熼梻瀵稿妽闁哄懏绻堥弻銊╁即閻愭祴鍋撻幖浣歌Е鐟滅増甯掔粻鍦磼椤旀娼愭い搴℃娣囧﹪骞撻幒鏂库叺闂佸搫鏈惄顖炪€侀弴銏犖ч柛娑卞枤閳ь剝娅ｇ槐鎾存媴閻熺増鏆伴梺鐟板殩閹凤拷
    OFFLINE,//缂傚倸鍊搁崐鎼佸磹妞嬪海鐭嗗〒姘ｅ亾鐎规洘鍔欓幐濠冨緞鐏炵偓顔曢梻浣圭湽閸ㄧ粯鐏欓梺鍛婅壘缂嶅﹪鐛弽顐㈠灊閻熸瑥瀚烽埀顒€妫欐穱濠囧箵閹烘柨鈪甸梺鍝勬湰閻╊垶銆侀弴銏犖ч柛娑卞枤閳ь剝娅ｇ槐鎾存媴閻熺増鏆伴梺鐟板殩閹凤拷
    ONREPORT,//闂傚倸鍊峰ù鍥敋瑜忛幑銏ゅ箳濡も偓绾惧鏌ｉ弮鍌氬付缁炬儳顭烽弻锝夊箛椤掍焦鍎撻梺缁樺笒閻忔岸濡甸崟顖氱妞ゆ挾鍋涢～鈺呮⒑缁嬪尅宸ユい顓犲厴楠炲啴鎮滈挊澶岀杸闂佺粯顨呴悧蹇涘储閻㈠憡鈷掑┑鐘查婢ь垳鎲搁弶鍨殻鐎规洘绻傞オ浼村川椤栨粣绱插┑鐘灱濞夋盯鎳熼鐐插偍閻庢稒锕╁▓浠嬫煟閹邦厼顥嬬紒鎰閺屸剝鎷呯憴鍕３闂佽桨鐒﹂幑鍥极閹剧粯鏅搁柨鐕傛嫹
    ONCHANGE,//婵犵數濮烽弫鎼佸磻濞戙垺鍋ら柕濞у啫鐏婇悗鍏夊亾闁告洖鐏氶弲鐐烘⒑閸涘﹥澶勯柛瀣у亾闂佸搫顑呴柊锝夊蓟閺囷紕鐤€闁靛／鍜冪吹闂備礁纾划顖炲蓟閵娾晛鐓橀柟杈鹃檮閸嬫劙鏌熺紒妯虹瑲婵炲牜鍙冮幃璺侯潩椤撯€愁棟闂佸疇顫夐崹鍧楀箖濞嗘挸绾ч柟瀵稿С濞ｎ噣姊绘担铏瑰笡妞ゃ劌鎳橀弫鍐Ψ瑜夐崑鎾绘濞戞牕浠梺杞扮劍閹瑰洭寮幘缁樻櫢闁跨噦鎷�
    ONALARM,//闂傚倸鍊搁崐椋庣矆娓氣偓楠炲鏁嶉崟顓犵厯闂佺鎻梽鍕疾濠靛鐓忓┑鐐靛亾濞呮捇鏌℃担鍛婎棦闁哄矉缍佸顒勫箰鎼淬垹鏋戦梻浣哥－缁垶寮婚妸鈺佺厴闁硅揪闄勯崑鎰版煙缂佹ê绗氭繛鍫弮閹泛顫濋鈥愁棟闂佸疇顫夐崹鍧楀箖濞嗘挸绾ч柟瀵稿С濞ｎ噣姊绘担铏瑰笡妞ゃ劌鎳橀弫鍐Ψ瑜夐崑鎾绘濞戞牕浠梺杞扮劍閹瑰洭寮幘缁樻櫢闁跨噦鎷�
    PING,//闂傚倸鍊搁崐鎼併偑閹绢喖纾婚柛鏇ㄥ€嬪ú顏勎у璺猴功閺屽牓姊虹憴鍕姸濠殿喓鍊濆畷鎰節濮橆厾鍙嗛梺鍝勬川閸嬫盯鍩€椤掆偓閹芥粎鍒掗崼婵堟殕闁告洦鍓涢崢鍗炩攽閻愭潙鐏ョ€规洦鍓熷鎼佸Χ婢跺﹦鏌堥梺褰掓？閻掞箓鍩涢幋锔藉仯闁搞儻绲洪崑鎾诲礃闊厾绀嬮梻鍌欒兌閹虫捇宕甸弽顓炵闁跨噦鎷�
    ONCONTROL,//闂傚倸鍊搁崐鐑芥嚄閸洏鈧焦绻濋崶銊ュ壒闂佹悶鍎洪崜娆戠矆閸愵喗鐓忓┑鐐戝啫鏆欑紒鐘冲灴濮婂宕掑▎鎴М濠电姭鍋撻弶鍫涘妿娴犳碍绻濋悽闈涗哗妞ゆ洘绮庣槐鐐寸瑹閳ь剟鎮伴鑺ュ劅闁靛ǹ鍎欒椤法鎹勯悮瀛橆暭缂備礁宕悥濂稿箖濡ゅ懐宓侀柛顭戝枛婵酣姊虹涵鍛彧闁告梹顨婇崺鈧い鎺戝€归鐔兼煙閸戙倖瀚�
    ONCONFIG,//闂傚倸鍊搁崐鎼佸磹閻戣姤鍊块柨鏇楀亾妞ゎ厼鐏濊灒闁兼祴鏅濋悡瀣⒑閸撴彃浜濇繛鍙夛耿瀹曟垿顢旈崼鐔哄幈闂佹枼鏅涢崯浼村煡婢跺瞼纾奸柣妯哄船瀹撳棝鏌＄仦鍓ф创濠碉紕鍏橀、娑㈡倷閹碱厸鍋撳鍡欑瘈婵炲牆鐏濋弸鏃堟煕閵娿倗鐭欑€殿喛顕ч埥澶娢熼柨瀣澑闂備胶纭堕崜婵嬵敂閻戣棄顫呴柕蹇嬪灮閿涙粌顪冮妶搴″箺閻㈩垱顨堥埀顒佺啲閹凤拷
    CONTROL,//婵犵數濮烽弫鎼佸磻閻愬搫鍨傞柛顐ｆ礀缁犱即鏌熼梻瀵歌窗闁轰礁瀚伴弻娑㈩敃閻樻彃濮岄梺閫炲苯鍘哥紒鑸靛哺閻涱喚鈧綆鍠楅弲婵嬫煃瑜滈崜娑氬垝鐠囪尙鏆﹂柛銉ｅ妼閺嬫垿鎮楅獮鍨姎妞わ富鍨跺浼村Ψ閿旇法绠氶梺闈涚墕閹冲繘宕抽崷顓犵＜闁绘ê宕畵鍡涙煛鐏炲墽娲村┑锛勫厴椤㈡盯鎮欓幖顓涘亾瀹ュ棛绡€婵炲牆鐏濆▍娆撴煙閸戙倖瀚�
    CONFIG//婵犵數濮烽弫鎼佸磻閻愬搫鍨傞柛顐ｆ礀缁犱即鏌熼梻瀵歌窗闁轰礁瀚伴弻娑㈩敃閻樻彃濮岄梺閫炲苯鍘哥紒鑸靛哺閻涱喚鈧綆鍠楅弲婊堟煟閿濆懓瀚伴悽顖氶叄閺岋絾鎯旈敍鍕殯闂佺ǹ楠稿畷顒傚弲闂侀潧艌閺呮盯宕欓悩缁樼厱鐎光偓閳ь剟宕戦悙鐑樺亗婵炲棙鍨圭壕濂告倵閿濆骸浜滄い鏇熺矒閺岋綁顢橀悤浣圭杹闂佸搫鐬奸崰鎾诲箯鐎ｎ剚鍠嗛柛鏇ㄥ亽娴硷拷
} TOPIC_MOD_T;

typedef struct
{
    uint8_t imei[16];
    uint8_t imsi[16];
    uint8_t ccid[32];
    uint8_t csq;
    uint8_t sim_status; /// 
    uint8_t net_status; /// 0.
    uint8_t ipv4_cid;
    uint8_t init_time; //
    LUAT_MQTT_STATE_E mqtt_status;
    luat_rtos_mutex_t mutex;
} DEV_LTE_T;
typedef struct
{
    uint16_t  mcc;
    uint16_t  mnc;
    uint16_t  lac;
    uint32_t  cid;
    int16_t rsrq;
    int16_t rssi;
    luat_rtos_mutex_t mutex;
} DEV_BSLOC_T;



#define MQTT_QUEUE_SIZE 128
#define MAX_TOPIC_LEN 32
//void dev_param_init(void);
void my_mqtt_init(void);
void usr_mqtt_pub_msg(char *msg, char *topic);
void usr_mqtt_switch_server(char *ip, char *port, char *name, char *passwd);
LUAT_MQTT_STATE_E get_mqtt_status(DEV_LTE_T *lte);

void usr_mqtt_task(void *param);
// char *get_topic(uint8_t mode);
#endif /* __USR_MQTT_H */
